package com.bootdo.system.controller;

import java.util.List;
import java.util.Map;

import com.bootdo.common.utils.ConversionUtil;
import com.bootdo.system.vo.ResultInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.parameters.P;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.system.domain.DlMemberDO;
import com.bootdo.system.service.DlMemberService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-06-02 13:39:57
 */
 
@Controller
@RequestMapping("/system/dlMember")
public class DlMemberController {
	@Autowired
	private DlMemberService dlMemberService;
	@Value("${upload.IP}")
	private String IP;

	@GetMapping()
	@RequiresPermissions("system:dlMember:dlMember")
	String DlMember(){
	    return "system/dlMember/dlMember";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:dlMember:dlMember")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<DlMemberDO> dlMemberList = dlMemberService.list(query);
		int count = dlMemberService.count(query);
		PageUtils pageUtils = new PageUtils(dlMemberList, count);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:dlMember:add")
	String add(){
	    return "system/dlMember/add";
	}

	@GetMapping("/edit/{memberId}")
//	@RequiresPermissions("system:dlMember:edit")
	String edit(@PathVariable("memberId") Integer memberId,Model model){
		DlMemberDO dlMember = dlMemberService.get(memberId);
		dlMember.setAvatar(ConversionUtil.dealWithUrl(dlMember.getAvatar(), IP));
		model.addAttribute("dlMember", dlMember);
	    return "system/dlMember/edit";
	}

	@GetMapping("/jobSeekers/{memberId}")
	public String jobSeekers(Model model, @PathVariable("memberId") String memberId){
		model.addAttribute("memberId", memberId);
		return "system/dlMember/jobSeekers";
	}

	/**
	 * 功能描述: 在线简历
	 *
	 * @Param: [memberId]
	 * @Return: com.ncxhr.logic.vo.ResultInfo
	 * @Author: 况鑫威
	 * @Date: 2021/4/20
	 * @Time: 11:25
	 */
	@ResponseBody
	@PostMapping("/getResume")
	public ResultInfo getResume(Integer memberId) {
		return new ResultInfo(dlMemberService.getResume(memberId));
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:dlMember:add")
	public R save( DlMemberDO dlMember){
		if(dlMemberService.save(dlMember)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@PostMapping("/update")
//	@RequiresPermissions("system:dlMember:edit")
	public R update( DlMemberDO dlMember){
		dlMemberService.update(dlMember);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:dlMember:remove")
	public R remove( Integer memberId){
		if(dlMemberService.remove(memberId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:dlMember:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] memberIds){
		dlMemberService.batchRemove(memberIds);
		return R.ok();
	}
	
}
